<template>
  <div>
    <div class="food" :style="foodHeight">
      <div class="menu-wrapper">
        <ul>
          <li class="menu-item select">
            <div class="text">
              尚粤粥铺
            </div>
          </li>
          <li class="menu-item">
            <div class="text">
              等待签约
            </div>
          </li>
        </ul>
      </div>
      <div class="food-wrapper" ref="foodscroll">
        <div>
          <div class="title">
            尚粤粥铺
          </div>
          <div class="foodg">
            <ul>
              <li class="fooditem" v-for="(food , index) in foods" :key="index">
                <div class="img">
                  <img :src="food.imgFood" alt="">
                </div>
                <div class="content">
                  <div class="name">{{food.foodName}}</div>
                  <div class="desc">{{food.foodId}}</div>
                  <div class="price">￥{{food.price}}</div>
                </div>
                <cartcontroller class="cartcontroller" :food="food"></cartcontroller>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <shopcart :user="user" :selectFoods="selectFoods"></shopcart>
  </div>
</template>

<script type="text/ecmascript-6">
  import BScroll from 'better-scroll';
  import shopcart from '../shopcart/shopcart';
  import cartcontroller from '../countcontroller/countcontroller';

  export default {
    props: {
      user: {}
    },
    data() {
      return {
        foods: []
      };
    },
    computed: {
      foodHeight() {
        return `height:${window.outerHeight - 46 - 174}px`;
      },
      selectFoods() {
        let selectFoods = [];
        this.foods.forEach((food) => {
          if (food.count) {
            selectFoods.push(food);
          }
        });
        return selectFoods;
      }
    },
   async created() {
      const response = await this.$store.food.list();
      this.foods = response;
      this.$nextTick(() => {
        this.menuScroll = new BScroll(this.$refs.foodscroll, {
          click: true
        })
        ;
      });
    },
    components: {
      shopcart,
      cartcontroller
    },
    methods: {
      switchfood() {
        this.foods = [
          {
            avatarimg: 'http://fuss10.elemecdn.com/6/72/cb844f0bb60c502c6d5c05e0bddf5jpeg.jpeg?imageView2/1/w/114/h/114',
            name: 'switchjoker',
            desc: 'switchjokerswitchjokerswitchjoker',
            price: '666'
          }
        ];
      }
    }
  };
</script>

<style lang="stylus" type="text/stylus" rel="stylesheet/stylus">
  .food
    display flex
    width 100%
    overflow hidden
    .menu-wrapper
      flex 0 0 80px
      background-color #f3f5f7
      width 80px
      .menu-item
        display: table
        height: 54px
        width 100%
        padding 0 12px
        line-height: 14px
        &.select
          background #FFFFFF
        .text
          display table-cell
          vertical-align middle
          width: 56px
          border-bottom 1px solid rgba(7, 17, 27, 0.1)
          font-size: 12px
          font-weight 200
          line-height 14px
    .food-wrapper
      flex 1
      .foodg
        .fooditem
          position relative
          border-bottom 1px solid rgba(7, 17, 27, 0.1)
          margin 18px 18px 0 18px
          .img
            vertical-align top
            display inline-block
            margin-bottom 18px
            img
              width 57px
              height 57px
          .content
            display inline-block
            margin-left 10px
            .name
              font-size 14px
              color rgb(7, 17, 27)
              line-height 14px
              margin-top 2px
            .desc
              color rgb(147, 153, 159)
              font-size 10px
              line-height 10px
              margin 8px 0
            .price
              font-size 14px
              font-weight 700
              color rgb(240, 20, 20)
          .cartcontroller
            position absolute
            right 13px
            bottom 13px
      .title
        /*border-left 2px solid #d9d1e1*/
        height 30px
        line-height 30px
        background #f3f5f7
        color rgb(147, 153, 159)
        padding-left 14px
        font-size 14px

  .comfimshop
    position fixed
    top 0
    left 0
    z-index 100
    width 100%
    height 100%
    background-color rgba(7, 17, 27, 0.8);
</style>
